package com.utils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.HashMap;

/**
 * <p>
 * Title:
 * </p>
 * 
 * <p>
 * Description:
 * </p>
 * 
 * <p>
 * Copyright: Copyright (c) 2006
 * </p>
 * 
 * <p>
 * Company:
 * </p>
 * 
 * @author not attributable
 * @version 1.0
 */
public class CorpTypeUtil {
	public CorpTypeUtil() {
	}

	public static HashMap corpTypeMap = new HashMap();

	public static String getCorpTypeName(String typeId) {
		if (corpTypeMap.isEmpty()) {
			getCorpTypeMap();
		}
		return (String) corpTypeMap.get(typeId);
	}
	public static String getColValueByQyid(String col ,String qyid){
		String value = "";
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		Connection con = null;
		String sql = "select * from qy_jbqk where qyid='" + qyid + "'";
		try {
			con = ConnectionManager.getConnection();
			pstmt = con.prepareStatement(sql);
			rs = pstmt.executeQuery();
			while (rs.next()) {
				value = rs.getString(col).trim();
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				rs.close();
				pstmt.close();
				con.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return value;
	}

	public static String getQylxByQyid(String qyid){
		String qylx = "";
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		Connection con = null;
		String sql = "select * from qy_jbqk where qyid='" + qyid + "'";
		try {
			con = ConnectionManager.getConnection();
			pstmt = con.prepareStatement(sql);
			rs = pstmt.executeQuery();
			while (rs.next()) {
				qylx = rs.getString("qylx").trim();
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				rs.close();
				pstmt.close();
				con.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return qylx;
	}
	
	public static String getSffrByQyid(String qyid){
		String sffr = "";
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		Connection con = null;
		String sql = "select * from qy_jbqk where qyid='" + qyid + "'";
		try {
			con = ConnectionManager.getConnection();
			pstmt = con.prepareStatement(sql);
			rs = pstmt.executeQuery();
			while (rs.next()) {
				sffr = rs.getString("sffr").trim();
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				rs.close();
				pstmt.close();
				con.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return sffr;
	}

	public static String getCorpParent(String typeId) {
		String parentid = "";
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		Connection con = null;
		String sql = "select * from sys_hyfl where hyfl='" + typeId + "'";
		try {
			con = ConnectionManager.getConnection();
			pstmt = con.prepareStatement(sql);
			rs = pstmt.executeQuery();
			while (rs.next()) {
				parentid = rs.getString("parentid").trim();
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				rs.close();
				pstmt.close();
				con.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return parentid;
	}

	public static void getCorpTypeMap() {
		Connection con = null;
		PreparedStatement pstmt = null;
		String sql = "select * from sys_hyfl order by hyfl";
		try {
			con = ConnectionManager.getConnection();
			pstmt = con.prepareStatement(sql);
			ResultSet rs = pstmt.executeQuery();
			while (rs.next()) {
				String hyfl = rs.getString("hyfl");
				String hyflmc = rs.getString("hyflmc");
				corpTypeMap.put(hyfl, hyflmc);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				pstmt.close();
				con.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

	}
}
